angular.module('imsApp').controller('channelsStatisticsController', ['$scope', '$rootScope', '$state', 'ChannelsManager', 'ImsDialog', 'ImsAlert', function ($scope, $rootScope, $state, ChannelsManager, ImsDialog, ImsAlert) {
    $scope.search = {
        pageNo: $state.params.pageNo || 1,
        pageSize: $state.params.pageSize || 10,
        channelId: $state.params.channelId,
        timeType: $state.params.timeType || "day"
    };
    $scope.paginationConf = {
        currentPage: $state.params.pageNo || 1,
        itemsPerPage: $state.params.pageSize || 10,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name,$scope.search)
        }
    };

    $scope.timeTypeChange=function (timeType) {
        $scope.search.pageNo=1;
        $scope.search.timeType=timeType;
        $state.go($state.current.name,$scope.search)
    }


    ChannelsManager.channelsStats([$scope.search.channelId, $scope.search.pageNo, $scope.search.pageSize], {timeType: $scope.search.timeType}).then(function (result) {
        console.log(result)
        $scope.total = result.data.countStat;
        $scope.title = result.data.title;
        $scope.lists = result.data.pageList;
        $scope.paginationConf.totalItems = result.data.total;

    })


}])

